export default {

  methods :{
/**
 *
 *
 * 带千分符，保留2位小数
 * 
 * 
 */
 toThousandDecimalFilter (num: string | number) {
  // debugger
 let DataArry = [];
 let string = '';
 let negativeValue = false;
 let floatPart = "";
 let intPart = "";
 if (num == 0) {
   string = '0.00'
   return string;
 }
 if (num) {
   num = num.toString();
   if (num.charAt(0) == '-') {
     negativeValue = true;
   }

   num = num.replace(/[^0-9.]/g, '');
   DataArry = num.split(".");
   if (DataArry[0]) {
     if (DataArry[0].length > 1) {
       let intPartArry:any = DataArry[0];
       let intPartArryIndex:any = 0;
       let isZero = true;
       for (let i in intPartArry) {
         if (intPartArry.charAt(i) != 0) {
           intPartArryIndex = i;
           isZero = false
           break;
         }
       }
       if (isZero) {
         intPart = '0'
       } else {
         intPart = intPartArry.substring(intPartArryIndex)
       }

     } else {
       intPart = DataArry[0]
     }
   } else {
     intPart = '0'
   }
   intPart = intPart.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,")
   if (DataArry[1]) {
     switch (DataArry[1].length) {
       case 0:
         floatPart = "00";
         break;
       case 1:
         floatPart = DataArry[1] + "0";
         break;
       default:
         floatPart = DataArry[1].substring(0, 2)
         break;
     }
   } else {
     floatPart = "00";
   }
   string = intPart + '.' + floatPart;
   if (negativeValue == true) {
     string = '-' + string
   }
 }
 return string;
},
/**
*
*
* 去除千分符，保留2位小数
* 
* 
*/
removeThousandDecimalFilter (num: string) {
 let DataArry = [];
 let string = '';
 let negativeValue = false;
 let floatPart = "";
 let intPart = "";
 if (num) {

   num = num.toString();

   if (num.charAt(0) == '-') {
     negativeValue = true;
   }
   num = num.replace(/[^0-9.]/g, '');
   DataArry = num.split(".");
   if (DataArry[0]) {
     if (DataArry[0].length > 1) {
       let intPartArry:any = DataArry[0];
       let intPartArryIndex:any = 0;
       let isZero = true;
       for (let i in intPartArry) {
         if (intPartArry.charAt(i) != 0) {
           intPartArryIndex = i;
           isZero = false
           break;
         }
       }
       if (isZero) {
         intPart = '0'
       } else {
         intPart = intPartArry.substring(intPartArryIndex)
       }

     } else {
       intPart = DataArry[0]
     }
   } else {
     intPart = '0'
   }
   if (DataArry[1]) {
     switch (DataArry[1].length) {
       case 0:
         floatPart = "00";
         break;
       case 1:
         floatPart = DataArry[1] + "0";
         break;
       default:
         floatPart = DataArry[1].substring(0, 2)
         break;
     }
   } else {
     floatPart = "00";
   }
   string = intPart + '.' + floatPart;

   if (negativeValue == true) {
     string = '-' + string
   }
 }
 return string;
}
  }




}



